<template>
	<view class="findpu_info">
		<view class="scroll_people">
			<view class="scroll_people_head" :style="'padding-top:'+ (statusBarHeight+20) +'rpx;'+ 'background-image: url(https://oss.yanhuangernv.com/zpupload/20240102/3ca9906e8f012aab0c.png)'">				
				<view class="zupus_item flex ali-c" @tap="toFamily(item)" v-for="(item,index) in info_zupu_list" :key="index"hover-class="none">	
					<view class="itemimgss">
						<image class="zpimgs"
							:style="{backgroundImage:'url('+photo_cdn1+'zpupload/static/zupu/pushu.png)'}"
							mode=""></image>
						<view class="family_name">{{item.family_name + '氏族谱'}}</view>
					</view>
					<view class="zupus_item_info flex1">
						<view class="zupu_names">{{item.family_name + '氏族谱'}}</view>
						<view class="flex ali-c jus-b fqr_text">
							<view class="">发起人：{{item.realname}} (传承人)</view>
							<!-- <view @tap.stop="contactInheritorn(item)" v-if="item.fastim_id" class="contactccr">联系第一传承人</view> -->
						</view>
				
						<view class="rprs_text">入谱人数：{{item.join_number}}</view>
						<view class="create_time">创建日期：{{item.createtime | parsetime}}</view>
						
						
						<view style="" style=" margin-top: 20rpx;">
							<view  class="apply1"  @tap.stop="toFamily1(item)" >
								进入族谱
							</view>
						</view>
						
						<view class="apply" @tap.stop="apply_for">申请入谱</view>
					</view>
				</view>
				

				
				<view class="ethnictraining" v-show="info_zupu_list.info.family_regulation">
					<view class="ethnictraining_info">祖训族规:</view>
					<view class="ethnictraining_info ethnictraining_con">{{info_zupu_list.info.family_regulation}}</view>
				</view>
			</view>
			

			<view class="browse_num">
				<view class="browse_avtar">
					<view class="avtar_list">

					</view>
					<view class="avtar_more">
						<view class="small"></view>
						<view class="small"></view>
						<view class="small"></view>
					</view>
				</view>
				<view class="browse_text">累计 {{look_num}} 人查阅</view>
			</view>
		</view>
		
		<references ref="references"  :source_type="source_type" :family_id="info_zupu_list.info.id"  :activation_code="info_zupu_list.info.code" ></references>
		
		<reference ref="reference"  :source_type="source_type" :family_id="family_id"  :activation_code="sm_namecard.activation_code" ></reference>

		<login :hidden="isshowlogin" @close="closefun" @loginsucc="loginsucc"></login>
	</view>
</template>

<script>
	import {
		getFamilyDetail
	} from "@/utils/api/zupu.js";
	import config from "@/utils/config.js";
	let {
		staticurl,
		photo_cdn1
	} = config.baseUrl;
	export default {
		data() {
			return {
				photo_cdn1,
				info_zupu_list: {info:{}},
				family_id: '',
				look_num: 0,
				isshowlogin: false,
				isshowtop: false,
				statusBarHeight: 0, //状态栏高度
				sm_namecard:{},//扫码查出来的族谱的信息
				source_type:"3",//3默认  2姓名卡
				codedata:'' //code码内容
			}
		},
		onLoad(option) {
			this.statusBarHeight = uni.getSystemInfoSync().statusBarHeight * 2;
			this.family_id = option.family_id ? option.family_id : '';			
			let sm_namecard = uni.getStorageSync("sm_namecard");
			sm_namecard = sm_namecard?sm_namecard:{};
			this.sm_namecard = sm_namecard;
			if(this.sm_namecard.card_number){
				this.source_type = 2;
			}
			
			//自动弹出加入族谱弹窗
			if(option.isopen==1){
				setTimeout(()=>{
					let token = uni.getStorageSync("token")
					if (!token) {
						this.isshowlogin = true;
						return;
					}
					this.$refs.reference.open();
				},2000)
			}
			this.getFamilyDetailfun();
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
			if (e.scrollTop > 100) {
				this.isshowtop = true;
			} else {
				this.isshowtop = false;
			}
		},
		methods: {
			getFamilyDetailfun() {
				getFamilyDetail({
					family_id: Number(this.family_id)
				}).then((res) => {
					if (res.code == 1) {
						this.info_zupu_list = res.data;
						this.look_num = res.data.info.read_records;
					} else {

					}
				})
			},
			toFamily1(item) {
				
				
				this.$refs.references.open();
				
				// if (this.codedata == '') {
				// 	this.$api.msg("密码口令不得为空!");
				// 	return false;
				// }
				
				// if (this.codedata !=  item.code){
				// 	this.$api.msg("口令密码错误！");
				// 	return false;
				// }
				
				// uni.navigateTo({
				// 	url: `/pages/zupu/familytrees/familytrees?family_id=${item.id}&code=${this.codedata}`
				// })
			},
			//查看族谱
			toFamily(item) {
				if (!item.is_show) {
					this.$api.msg("你没有访问权限!");
					return false;
				}

				uni.navigateTo({
					url: `/pages/zupu/familytrees/familytrees?family_id=${item.id}`
				})
			},
			//申请入谱
			apply_for() {
				let token = uni.getStorageSync("token")
				if (!token) {
					this.isshowlogin = true;
					return;
				}
				this.$refs.reference.open();
			},
			//关闭授权登录弹窗
			closefun() {
				this.isshowlogin = false;
			},
			//登录完成
			loginsucc() {

			},
			toback(){
				uni.navigateBack()
			}
		}
	}
</script>

<style lang="scss">
	@import "./findpu_info.scss"
</style>